<?php
/**
 * OssService.php
 * 文件描述 对象储存管理服务类
 * Created on 2020/9/4 9:15
 * Created by 刘小龙 595929049@qq.com
 */

namespace app\common\services;


use AlibabaCloud\Client\AlibabaCloud;
use app\common\helpers\Response;
use Carbon\Carbon;
use think\facade\Filesystem;
use think\File;

class OssService
{
    private $disk = 'aliyun';   // 储存磁盘，默认阿里云

    public function __construct()
    {
        $this->disk = config('filesystem.default');
    }

    /**
     * @todo 图片上传
     * @param File $image           图片文件
     * @param string $path_prefix   路径前缀：可用于规定图片的分类位置
     * @return bool|string
     */
    public function uploadImage(File $image, string $path_prefix = '')
    {
        $path = $path_prefix . Carbon::now()->format('Y/m/d');
        $save = Filesystem::disk($this->disk)->putFile($path, $image);
        return Filesystem::disk($this->disk)->getUrl($save);
    }
}
